home *** CD-ROM | disk | FTP | other *** search
/ Popular Request / By Popular Request (Arsenal Computer)(SysOptics Distribution System).ISO / amiga1 / ami_n086.lha / output.c < prev    next >
C/C++ Source or Header  |  1993-11-23  |  2KB  |  57 lines

  1. #include "global.h"
  2. void write_files(files)
  3.      Name *files;
  4. {
  5.   while (files) {
  6.     write_files(files->llink);
  7.     {
  8.       char indent_chars[500];
  9.       FILE *temp_file;
  10. //      char *temp_name = tempnam(".", 0);
  11. //tcw
  12.       char *temp_name = tmpnam(NULL); //tcw fixed for ANSI,
  13.  
  14. // bump temp_name by 2 to get past the "t:" that is tacked on by SASC : tcw
  15.       temp_name += 2; // a hack! tcw
  16.       temp_file = fopen(temp_name, "w");
  17.       if (!temp_file) {
  18.         fprintf(stderr, "%s: can't create %s for a temporary file\n",
  19.                 command_name, temp_name);
  20.         exit(-1);
  21.       }  
  22.       if (verbose_flag)
  23.         fprintf(stderr, "writing %s\n", files->spelling);
  24.       write_scraps(temp_file, files->defs, 0, indent_chars,
  25.                    files->debug_flag, files->tab_flag, files->indent_flag);
  26.       fclose(temp_file);
  27.       if (compare_flag)
  28.         {
  29.           FILE *old_file = fopen(files->spelling, "r");
  30.           if (old_file) {
  31.             int x, y;
  32.             temp_file = fopen(temp_name, "r");
  33.             do {
  34.               x = getc(old_file);
  35.               y = getc(temp_file);
  36.             } while (x == y && x != EOF);
  37.             fclose(old_file);
  38.             fclose(temp_file);
  39.             if (x == y)
  40.               remove(temp_name);
  41.             else {
  42.               remove(files->spelling);
  43.               rename(temp_name, files->spelling);
  44.             }
  45.           }
  46.           else
  47.             rename(temp_name, files->spelling);
  48.         }
  49.       else {
  50.         remove(files->spelling);
  51.         rename(temp_name, files->spelling);
  52.       }
  53.     }
  54.     files = files->rlink;
  55.   }
  56. }
  57.